﻿﻿<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/taglib.jsp"%>
<%@ page import="java.util.*,cn.ac.cintcm.dataconverge.researcher.domain.Organization,com.hs.core.page.PageUtil,com.hs.core.utils.StringUtilTool,cn.ac.cintcm.dataconverge.researchsubject.domain.SubRes" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String imagePath = path + "/index/";

PageUtil pageUtil = (PageUtil)request.getAttribute("pageUtil");
if(pageUtil == null)
  pageUtil = new PageUtil();

  List list = pageUtil.getPageList();
  list = (List)request.getAttribute("subResList");
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>DataConverge</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <script language="javascript" src="<%=path %>/index/Scripts/script.js"></script>
	<script language="javascript" src="<%=path %>/js/common.js"></script>
	<link href="<%=path %>/index/Themes/com/style.css" type="text/css" rel="stylesheet"></link>
    <script type="text/javascript">
      var xmlHttp;
      var url="";
      var delNode;
      //var nameArray=new Array();
      function lookMe(thisTag){
		var span = thisTag.getElementsByTagName('span')[0];
		span.style.display = 'block';
		thisTag.onmouseout = function(){
			span.style.display = 'none';
		}
	}

function mouseMove(event){
	var xx=event.clientX + 5;
	var yy=event.clientY + 10;
	var obj = event.srcElement ? event.srcElement : event.target;
        var span=obj.getElementsByTagName("span")[0];
	span.style.left = xx + 'px';
	span.style.top = yy + 'px';
}


      function createXMLHttpRequest() {
			if (xmlHttp == null) {
	    		if (window.ActiveXObject) {
	    			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	    		}
	    		else if (window.XMLHttpRequest) {
	        		xmlHttp = new XMLHttpRequest();                
	    		}
    		}
	  }
			  
      function change(){
      		var orgId=document.form0.org.value;
      		var zhicheng=document.form0.zhicheng.value;
      		var name=document.form0.name.value;
      		//alert("org id is "+orgId+" zhicheng is "+zhicheng+" name is "+name);
            url="subject.htm?action=getResearchers&orgId="+orgId+"&zhicheng="+zhicheng+"&name="+escape(name);
     	    createXMLHttpRequest();
			xmlHttp.open("GET", url, true);
    		xmlHttp.onreadystatechange = callback;
    		xmlHttp.send(null);
      }
      
     /* function searchName(event){
      	if(event.keyCode==13) {
      	  alert("yes");	change();
      	}
      }*/
      
      function callback(){
      	if(xmlHttp.readyState==4){
    			if(xmlHttp.status==200){
    				clearResults();
    				parseMessage();
    			}
    		}
      }
      function researchersObj(){
         var dept = '&nbsp;';
         var zhicheng = '&nbsp;';
		 var major = '&nbsp;';
      }
      function parseMessage(){
      		var xmlDoc = xmlHttp.responseXML;
			var nodes = xmlDoc.getElementsByTagName('researcher');
			var res=document.getElementById("researchers");
			if(nodes!=null){
				var id="";
				var name="";
				var detail="";
				var tr;
				for(var i=0;i<nodes.length;i++){
					//id=nodes[i].firstChild.firstChild.nodeValue;
					//name=nodes[i].nextChild.firstChild.nodeValue;
					//detail=nodes[i].lastChild.firstChild.nodeValue;
					id=nodes[i].getElementsByTagName("id")[0].firstChild.nodeValue;
					name=nodes[i].getElementsByTagName("name")[0].firstChild.nodeValue;
					detail=nodes[i].getElementsByTagName("detail")[0].firstChild.nodeValue;
					var resObj =new researchersObj();
					if(nodes[i].getElementsByTagName("dept")[0].firstChild != null)
						resObj.dept = nodes[i].getElementsByTagName("dept")[0].firstChild.nodeValue;
					else resObj.dept="";
					if(nodes[i].getElementsByTagName("zhicheng")[0].firstChild != null)
						resObj.zhicheng = nodes[i].getElementsByTagName("zhicheng")[0].firstChild.nodeValue;
					else resObj.zhicheng="";
					if(nodes[i].getElementsByTagName("major")[0].firstChild != null)
						resObj.major = nodes[i].getElementsByTagName("major")[0].firstChild.nodeValue;
						else resObj.major="";
					if(i%12==0){
						tr = res.insertRow(res.rows.length);
					}
					
					addResN(id,name,detail,tr,resObj);					
					//addRes(id,name);
				
				}
			}			
      }
      function researcherChick(id){
	      if(id==null)
	      return ;
	      var cid =document.getElementById("researcher-"+id);
	      if(cid != null)
	      	if(cid.checked)cid.checked = false;
	      	else cid.checked = true;
      }
      function addResN(id,name,detail,parentNode,resObj){
      	var td= parentNode.insertCell();
      	td.innerHTML=
      	'<div onmouseover="lookMe(this);" class="lookMe" onmousemove="mouseMove(event);">'+
      	'<input type="checkbox" name="researcher" id="researcher-'+id+'" value="'+id+'"><font style="cursor: hand" onclick="researcherChick('+id+');">'+name+'</font>'+
      	'<span>'+
      	'姓名:'+name+
      	'<br>部门:'+resObj.dept+
      	'<br>职称:'+resObj.zhicheng+
      	'<br>专业:'+resObj.major+
      	'</span>'+
      	'</div>';
      }
      
     /* function addRes(id,name){
     	var res=document.getElementById("researchers");
      	var input;
		var text;
       //alert("id is "+id+" name is "+name);
		input=document.createElement("input");
		input.type="checkbox";
		input.value=id;
		input.name="researcher";
		input.setAttribute("nameValue",name);
		//input.nameValue=name;
		res.appendChild(input);
		
		text = document.createTextNode(name);
		//text.name="resName";   
		res.appendChild(text); 
      }
      */
      function clearResults(){
         	var res=document.getElementById("researchers");
         	while(res.childNodes.length > 0) {
				res.removeChild(res.childNodes[0]);
			}
      }
      
    /*  function filter(){
      	 var res=document.getElementById("researchers");
      	 var name=document.form0.name.value;//alert("input:"+name);
      	 if(name==""){
      	 	return;
      	 }
      	 var _name="";
      	 var count=0;
      	 while(res.childNodes.length > 0) {
      	 		//alert("count is "+count);
      	 		if(count>=res.childNodes.length){
      	 			return;
      	 		}
      	 		_name=res.childNodes[count].nameValue;
      	 		if(_name.indexOf(name)==-1){
					res.removeChild(res.childNodes[count]);
					res.removeChild(res.childNodes[count]);
				}else{
					count=count+2;
				}			
		 }
      }*/
      
      function addResearchers(){
        var researcherIds="";
   
        var trs=document.getElementsByName("researcher");
		for(var i=0;i<trs.length;i++){
				var checkb=trs[i];
				if(checkb.checked){
					researcherIds += checkb.value+";";
				}
		}
		if(researcherIds==""){
			alert("请选择至少一个科研人员");
			return;
		}
		//alert(researcherIds);
		var role=document.form0.role.value;
		var orderNum=document.form0.orderNum.value;
		if(!checkSeq(orderNum)){
			return;
		}
		url="subject.htm?action=addResearchers&researcherIds="+researcherIds+"&role="+escape(role)+"&orderNum="+orderNum;
		//alert(url);
		createXMLHttpRequest();
		xmlHttp.open("GET", url, true);
    	xmlHttp.onreadystatechange = callbackForAddResearcher;
    	xmlHttp.send(null);
      }
      
      function checkSeq(seq){
      	var exp = new RegExp("^[0-9]{1,4}$");
      	if(seq!="" && !exp.test(seq)){
      		alert("请输入有效的顺序号，顺序号必须是整数");
      		return false;
      	}
      	return true;
      }
      
      function callbackForAddResearcher(){
      	if(xmlHttp.readyState==4){
    			if(xmlHttp.status==200){
    				var xmlDoc = xmlHttp.responseXML;
					var nodes = xmlDoc.getElementsByTagName('researcherAdded');
					var added=nodes[0].firstChild.nodeValue;
					if(added>0){					
    					alert("已成功添加"+added+"名科研人员");
    					var page=2;
      					var id=document.form0.subjectId.value;
                                        
      					document.location.href ="subject.htm?action=gotoAddResearcher&subjectId="+id+"&page="+page;
    				}else{
      					var errMsg=xmlDoc.getElementsByTagName('errMsg')[0].firstChild.nodeValue;
      					alert(errMsg);
      				}
    			}
    	}
      }
      
     /*function clearName(){
     	document.form0.name.value="";
     	document.form0.name.focus();
     }*/
     function delSubRes(subResId,node){
     	if(!window.confirm("确定删除？","确定","取消"))	
        return;
      	url="subject.htm?action=delSubRes&subResId="+subResId;
      	delNode=node.parentNode.parentNode;
      	createXMLHttpRequest();
		xmlHttp.open("GET", url, true);
    	xmlHttp.onreadystatechange = callbackForDelSubRes;
    	xmlHttp.send(null);
      }
      
      function callbackForDelSubRes(){
      	if(xmlHttp.readyState==4){
    			if(xmlHttp.status==200){
    				var xmlDoc = xmlHttp.responseXML;
					var nodes = xmlDoc.getElementsByTagName('subResDeleted');
					var deleted=nodes[0].firstChild.nodeValue;					
    				if(deleted==1){
    					delNode.parentNode.removeChild(delNode);
    				}else{
      					var errMsg=xmlDoc.getElementsByTagName('errMsg')[0].firstChild.nodeValue;
      					alert(errMsg);
      				}
    			}
    	}
      }
      
      function goback(){
      	var page=document.form0.page.value;
      	var subjectId=document.form0.subjectId.value;
      	if(page!="" && subjectId!=""){
      		//document.location.href='subject.htm?ec_p='+page;
      		document.location.href="subjectModify.htm?subjectId="+subjectId+"&page="+page;
      	}else{
      		document.location.href='subject.htm?ec_p='+page;;
      	}
      }
      
      function addNew(){
         var org=document.form0.org.value;
         var zhicheng=document.form0.zhicheng.value;
         var name=document.form0.name.value;
         var role=document.form0.role.value;
         if(org==''){
         alert("请选择此科研人员所属单位!");
         return false;
         }
         if(zhicheng==''){
         alert("请选择此科研人员的职称");
         return false;
         }
         if(name==''){
         alert("请输入此科研人员的姓名!");
         return false;
         }
         var seq=document.form0.orderNum.value;
		 if(!checkSeq(seq)){
			return;
		 }
		url="subject.htm?action=addNewResearcher&name="+escape(name)+"&org="+org+"&zhicheng="+zhicheng+"&role="+escape(role)+"&orderNum="+orderNum;
		//alert(url);
		createXMLHttpRequest();
		xmlHttp.open("GET", url, true);
    	xmlHttp.onreadystatechange = callbackForAddResearcher;
    	xmlHttp.send(null);
          
      }
      
      function chgOrd(subResId){
        if(!window.confirm("需要更改此科研人员的序号吗？","确定","取消"))	
            return;
        var name='resord'+subResId;
        var ord=document.getElementById(name).value;
        if (checkSeq(ord)) {
       	    url="subject.htm?action=chgOrder&subResId="+subResId+"&order="+ord;
      	    createXMLHttpRequest();
	    xmlHttp.open("GET", url, true);
    	    xmlHttp.onreadystatechange = callbackChgResOrd;
            xmlHttp.send(null);
      	}
      }
      
        function callbackChgResOrd(){
      	    if(xmlHttp.readyState==4){
    			if(xmlHttp.status==200){
   				var xmlDoc = xmlHttp.responseXML;
                                alert(xmlDoc.getElementsByTagName('errMsg')[0].firstChild.nodeValue);
      		       }
    	    }
    	}

	function goback(){
	  	document.location.href="subjectModify.htm?subjectId=${subjectId}";
	}

        function refresh(){
                var page=document.form0.page.value;
      		var id=document.form0.subjectId.value;
		document.location.href ="subject.htm?action=gotoAddResearcher&subjectId="+id+"&page="+page; 
        }
    </script>
    <style type="text/css">
.lookMe{
	color:#0099FF;
	cursor:pointer;
}
.lookMe span{
	display:none;
	position:absolute;
	/*left:50px;
	top:20px;*/
	padding:5px;
	width:200px;
	z-index:10000000000;
	color:#CC3300;
	background:#FFFADC;
	border:1px solid #CC6600;
}
</style>
  </head>
  <body class="rtm_body" onload="change();">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
            <td>
                <div class="content">
                    <table width="*" cellpadding="0"  cellspacing="1" class="dg_borderstyle" id="Table4">
                        <tr>
                            <td class="dg_headerstyle" width="5%">
                               	序号</td>
                            <td class="dg_headerstyle" width="35%">
                                 姓名</td>
                            <td class="dg_headerstyle" width="35%">
                                 职称</td>
                            <td class="dg_headerstyle">
                                角色</td> 
                            
                            <td class="dg_headerstyle">
                                删除</td> <% //如果课题状态为1 那么不允许删除 稍后完善  %>
                        </tr>
                        <% Iterator iterator = list.iterator(); 
                        int i =1;
                         while(iterator.hasNext()){
                        	 SubRes subRes = (SubRes)iterator.next();
                        %>
                        <tr class="dg_alternatingitemstyle">
                            <td> <input type="text" id="resord<%=subRes.getId() %>" size="5" value ="<%=subRes.getOrderNum() %>"/>
                         <a href="#"  onclick="chgOrd('<%=subRes.getId() %>');">改变序号</a></td>
                            <td>
                                <%=subRes.getRes().getName() %>
                            </td>
                            <td>
                                 <%=subRes.getRes().getZhicheng() %>
                            </td>
                            <td>
                               <%=subRes.getResRole() %>
                            </td>
                            
                            <td align="center">
                                <img style="cursor: hand" src="<%=imagePath %>Themes/com/68design.net_registration1_(delete)_16x16.gif" onclick="javaScript:delSubRes(<%=subRes.getId() %>,this);"
                                    alt="删除" />
                            </td> 
                        </tr> 
                        <%} %>
                    </table>  
                </div>
            </td>
        </tr>
    </table>
  
	
 <table cellpadding="0" cellspacing="0" width="100%" height="100%" id="Table8">
 <form name="form0">
     	<input type="hidden" name="subjectId" value="${subjectId}"/>
        <tr>
            <td valign="top" height="100%">
                <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" id="Table11">
                    <tr>
                        <td valign="top" >
                            <!------------------ 标题栏 ------------------>
                            <!--- 标题 ---->
                            <table class="idt_tle_mg" cellspacing="0" cellpadding="0" width="100%">
                                <tr onclick="javascript:OnShow(tdForm,imgForm6);">
                                    <td class="idt_tle_i">
                                        <img id="imgForm6" src="<%=basePath%>index/Themes/com/idt_tle_o.gif"></td>
                                    <td class="idt_tle_f1">
                                        添加科研人员</td>
                                </tr>
                            </table>
                            <!--- 内容 --->
                            <div id="tdForm">
                                <table border="0" cellpadding="0" cellspacing="1" width="100%" class="idt_fim_mg">
                                    <tr>
                                        <td class="fim_l">
                                           所在单位</td>
                                        <td class="fim_r">
	                                        <select name="org" onchange="changeOrg();">
					    					<c:forEach items="${orgList}" var="org" varStatus="loopStep">
						    					<option value="${org.id}"  
						    					<c:if test="${currentOrgId==org.id}">selected</c:if>><c:out value="${org.name}"/></option>;
						    				</c:forEach>
					    			   		</select>
                                        </td>
                                          <td class="fim_l">
                                           职称</td>
                                        <td class="fim_r" >
	                                       <select name="zhicheng" onchange="change();">
												<option value="">全部</option>
												<option value="1">正高</option>
												<option value="2">副高</option>
												<option value="3">中级</option>
												<option value="4">初级</option>
												<option value="5">其它</option>
											</select>
                                            </td>
                                    </tr>
                                    <tr>
                                        <td class="fim_l">
                                          姓名</td>
                                        <td class="fim_r" id="departments" colspan="3">
                                       		<input type="text" name="name" onkeyup="change();">注：输入姓名，可在以下列表中查询科研人员
                                         </td>
                                    </tr>
                                    <tr>
                                        <td class="fim_l">备选人<input type="checkbox" name="selectAll" value="1">全选</td>
                                        <td class="fim_r" colspan="3">
	                                       <TABLE id="researchers">
	                                       </TABLE>
                                            </td>
                                      </tr>
                                      <tr>
                                        <td class="fim_l">
                                            角色</td>
                                        <td  class="fim_r" colspan="3">
                                           <select name="role"><option value="参与人员">参与人员</option><option value="负责人">负责人</option></select>
 											&nbsp;&nbsp;顺序号：<input name="orderNum" id = "orderNum" type="text" size="5" value="${size}"/>（填一整数，如1，2等）
                                        &nbsp;&nbsp;
                                        <input type="button" value="添加到课题"  class="com_textbox"  onclick="addResearchers();">
                                           </td>
                                    </tr>
                                    <tr>
                                    <td colspan="4">
									  <font color="red">若科研人员在名单中找不到，请在上述姓名输入框中输入人员姓名并点击：</font>
										<input type="button"  name="sss" value="添加到课题"  class="com_textbox"  onclick="addNew();"/>
									</td>
									</tr>
                                </table>
                                <table cellspacing="0" cellpadding="0" width="100%" class="idt_bottom_mg" border="0">
                                    <tr>
                                        <td align="right">
                                            
                                        </td>
                                    </tr>
                                </table>
                            </div>
                </table></form>
  </body>
</html>
